local rende = fk.CreateSkill {

  name = "joy_mou__rende",

  tags = {  },

}


--[[
rende:addEffect("viewas", {
  pattern = ".",
  name = "joy_mou__rende",
  interaction = function(self,player)
    local choices = {}
    if player:getMark("@joy_mou__rende") > 1 and player:getMark("joy_mou__rende_vs-turn") == 0 then
      for _, name in ipairs(U.getAllCardNames("bt")) do
        local card = Fk:cloneCard(name)
        if (Fk.currentResponsePattern == nil and player:canUse(card)) or
        (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(card)) then
          if (card.type == Card.TypeBasic and player:getMark("@joy_mou__rende") > 1)
          or (card:isCommonTrick() and player:getMark("@joy_mou__rende") > 2) then
            table.insertIfNeed(choices, card.name)
          end
        end
      end
    end
    return UI.ComboBox {choices = choices}
  end,
  view_as = function(self)
    if not self.interaction.data then return nil end
    local c = Fk:cloneCard(self.interaction.data)
    c.skillName = rende.name
    return c
  end,
  before_use = function(self, player, use)
    local room = player.room
    room:removePlayerMark(player, "@joy_mou__rende", use.card.type == Card.TypeBasic and 2 or 3)
    room:setPlayerMark(player, "joy_mou__rende_used-turn", 1)
  end,
  enabled_at_play = function(self, player)
    return player:getMark("@joy_mou__rende") > 1 and player:getMark("joy_mou__rende_prohibit-turn") == 0
    and player:getMark("joy_mou__rende_used-turn") == 0
  end,
  enabled_at_response = function (self, player, response)
    return player:getMark("@joy_mou__rende") > 1 and player:getMark("joy_mou__rende_prohibit-turn") == 0
    and player:getMark("joy_mou__rende_used-turn") == 0
  end,
})
--]]
rende:addEffect("active", {
  name = "joy_mou__rende&",
  --rende,
  prompt = "#joy_mou__rende-give",
  target_num = 1,
  min_card_num = 1,
  card_filter = Util.TrueFunc,
  target_filter = function(self, player, to_select, selected)
    return #selected == 0 and to_select ~= player.id and #selected_cards > 0
    and Fk:currentRoom():getPlayerById(to_select):getMark("joy_mou__rende_target-phase") == 0
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    room:setPlayerMark(target, "joy_mou__rende_target-phase", 1)
    room:setPlayerMark(target, "joy_mou__rende_target", 1)
    room:moveCardTo(effect.cards, Player.Hand, target, fk.ReasonGive, rende.name, nil, false, player.id)
    if player.dead then return end
    room:setPlayerMark(player, "@joy_mou__rende", math.min(10, player:getMark("@joy_mou__rende") + #effect.cards))
  end,
  can_use = function (self, player, card)
    return player:getMark("joy_mou__rende_prohibit-turn") == 0
  end,
})
--

rende:addEffect(fk.EventPhaseStart, {
  name = "#joy_mou__rende_trigger",
  mute = true,
  --rende,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(rende.name) and target == player and player.phase == Player.Play and player:getMark("@joy_mou__rende") < 10
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("joy_mou__rende")
    room:setPlayerMark(player, "@joy_mou__rende", math.min(10, player:getMark("@joy_mou__rende") + 3))
  end,
})

return rende